﻿// GetCurrentDate.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

//#include <iostream>

#include "GetDateHeaders.h"

// Get current date/time, format is YYYY-MM-DD.HH:mm:ss
const string currentDateTime01() {
    time_t     now = time(0);
    struct tm  tstruct;
    char       buf[80];
    tstruct = *localtime(&now);
    // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
    // for more information about date/time format
    strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);

    return buf;
}

void test() {
    std::time_t t = std::time(0);   // get time now
    std::tm* now = std::localtime(&t);
    std::cout << (now->tm_year + 1900) << '-'
        << (now->tm_mon + 1) << '-'
        << now->tm_mday
        << "\n";
}


const string currentDateTime02()
{
    string re;

    // 基于当前系统的当前日期/时间
    time_t now = time(0);

    // 把 now 转换为字符串形式
    char* dt = ctime(&now);
    re.assign(dt, strlen(dt));
    return re;

    cout << "本地日期和时间：" << dt << endl;
}

const string currentDateTime03()
{
    string re;

    // 基于当前系统的当前日期/时间
    time_t now = time(0);

    // 把 now 转换为字符串形式
    char* dt = ctime(&now);

    // 把 now 转换为 tm 结构
    tm* gmtm = gmtime(&now);
    dt = asctime(gmtm);

    re.assign(dt, strlen(dt));
    return re;

    cout << "UTC 日期和时间：" << dt << endl;
}

const string currentDateTime04()
{
    ATL::CTime time = CTime::GetCurrentTime();
    string date;
   
    CString curdate = time.Format("%Y-%m-%d");
    date = (CStringA)curdate;
    return date;
}

